<script setup lang="ts">
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
//import ReloadPrompt from './ReloadPrompt.vue'
import mitt from "mitt";
import { darkTheme, lightTheme } from "naive-ui";
import {
  sendGiftMsg,
  sendGuardMsg,
  sendKeywordsMsg,
  sendRegularMsg,
  sendWelcomeMsg,
  clearRegularMsg
} from "@/views/utils/blive";

onBeforeUnmount(() => {
  window.electronAPI.removeAllEvent("blive:[Danmu]");
  window.electronAPI.removeAllEvent("blive:[Gift]");
  window.electronAPI.removeAllEvent("blive:[GuardBuy]");
  window.electronAPI.removeAllEvent("blive:[UserAction]");
  window.electronAPI.removeAllEvent("blive:[Open]");
  window.electronAPI.removeAllEvent("blive:[Close]");
});
init();
function init() {
  initEventBus();
}
function initEventBus() {
  window.$bus = mitt();
  window.electronAPI.addBliveEvent("Danmu", (event, value) => {
    window.$bus.emit("blive:Danmu", value);
    sendKeywordsMsg(value);
  });
  window.electronAPI.addBliveEvent("Gift", (event, value) => {
    window.$bus.emit("blive:Gift", value);
    sendGiftMsg(value);
  });
  window.electronAPI.addBliveEvent("GuardBuy", (event, value) => {
    window.$bus.emit("blive:GuardBuy", value);
    sendGuardMsg(value);
  });
  window.electronAPI.addBliveEvent("UserAction", (event, value) => {
    window.$bus.emit("blive:UserAction", value);
    sendWelcomeMsg(value);
  });
  window.electronAPI.addBliveEvent("Open", (event, value) => {
    window.$bus.emit("blive:Open", value);
    sendRegularMsg();
  });
  window.electronAPI.addBliveEvent("Close", (event, value) => {
    window.$bus.emit("blive:Close", value);
    clearRegularMsg();
  });
  window.electronAPI.addBliveEvent("Error", (event, value) => {
    console.log("blive[Error]:", value);
    window.$bus.emit("blive:Error", value);
  });
}
</script>

<template>
  <div class="wh-screen overflow-y-hidden">
    <n-config-provider :theme="lightTheme">
      <n-message-provider>
        <PageTransition />
      </n-message-provider>
    </n-config-provider>
  </div>
  <!-- <ReloadPrompt /> -->
</template>

<style>
@import "assets/css/normalize.css";
@import "assets/css/transition.css";
@import "assets/css/var.css";
@import "assets/css/tooltip.css";
@import "assets/css/scrollbar.css";

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  font-size: 16px;
}
.hide-scrollbar::-webkit-scrollbar {
  display: none;
}
img {
  object-fit: contain;
  object-position: bottom;
}
</style>
